home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / ncpfs / mars_dos.000 / mars_dos / netpc / map.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-21  |  7.5 KB  |  314 lines

  1. /* map.c 05-Apr-96 */
  2.  
  3. /****************************************************************
  4.  * (C)opyright (C) 1993,1996  Martin Stover, Marburg, Germany   *
  5.  ****************************************************************/
  6.  
  7. #include "net.h"
  8.  
  9. typedef struct {
  10.   uint8 connection;
  11.   uint8 volume;
  12.   uint8 buff[512];  /* complete path  */
  13.   uint8 *path;      /* points to path */
  14. } NWPATH;
  15.  
  16. static void show_map(uint8 *drvstr)
  17. {
  18.   int j;
  19.   for (j=0; j < 32; j++){
  20.     uint8 connid;
  21.     uint8 dhandle;
  22.     uint8 flags;
  23.     if (*drvstr && (j + 'A' != *drvstr)) continue;
  24.     if ((!get_drive_info(j, &connid, &dhandle, &flags)) && flags){
  25.       char  servern[52];
  26.       char  path[256];
  27.       servern[0]='\0';
  28.       if (flags & 0x80) { /* lokal DRIVE */
  29.         path[0]= '\\';
  30.         if (j < 2){
  31.           strcpy(path, "DISK LW");
  32.         } else if (getcurdir(j+1, path+1)) {
  33.           strcpy(path, "LW !OK");
  34.         }
  35.       } else {
  36.         if (get_dir_path(dhandle, path)) {
  37.           strcpy(path, "DHANDLE !OK");
  38.         }
  39.         if (connid) {
  40.           get_fs_name(connid, servern);
  41.           strcat(servern, "\\");
  42.         } else servern[0]='\0';
  43.       }
  44.       printf("MAP %c: = %s%s\n", (char)j+'A', servern, path);
  45.     }
  46.   }
  47. }
  48. #if 0
  49. static void do_map(int drive, NWPATH *nwp)
  50. {
  51.   if (drive > -1 && drive < 32) {
  52.     uint8 connid;
  53.     uint8 dhandle;
  54.     uint8 flags;
  55.     if ((!get_drive_info(drive, &connid, &dhandle, &flags)) && flags){
  56.       char  servern[52];
  57.       char  path[256];
  58.       if (flags & 0x80) { /* lokal DRIVE */
  59.         path[0]= '\\';
  60.         if (drive < 2){
  61.           strcpy(path, "DISK LW");
  62.         } else if (getcurdir(drive+1, path+1)) {
  63.           strcpy(path, "LW !OK");
  64.         }
  65.       } else {
  66.         if (get_dir_path(dhandle, path)) {
  67.           strcpy(path, "DHANDLE !OK");
  68.         }
  69.       }
  70.       if (connid) {
  71.         get_fs_name(connid, servern);
  72.         strcat(servern, "\\");
  73.       } else servern[0]='\0';
  74.       printf("DOMAP %c: = %s%s\n", (char)drive+'A', servern, path);
  75.     }
  76.   }
  77. }
  78. #endif
  79.  
  80. static int do_map(int drive, NWPATH *nwp, int delete)
  81. {
  82.   int result = -1;
  83.   if (drive > -1 && drive < 32) {
  84.     uint8 connid;
  85.     uint8 dhandle;
  86.     uint8 flags;
  87.     if (!delete ||
  88.       (!get_drive_info(drive, &connid, &dhandle, &flags) && flags && connid)){
  89.       uint8 nmdrive[3];
  90.       nmdrive[0] = drive+'A';
  91.       nmdrive[1] = ':';
  92.       nmdrive[2] = '\0';
  93.       result = redir_device_drive(delete ? -1 : 0x4, nmdrive, nwp->path);
  94.     }
  95.   }
  96.   return(result);
  97. }
  98.  
  99. static int parse_argv(uint8 *drvstr, NWPATH *nwpath,
  100.                   int argc, char *argv[], int smode, int argvmode)
  101. {
  102.   int k     = 0;
  103.   int mode  = 0;
  104.   uint8 *pd = drvstr;
  105.   *drvstr   = '\0';
  106.   memset(nwpath, 0, sizeof(NWPATH));
  107.   *(nwpath->buff) = '\0';
  108.   nwpath->path = nwpath->buff;
  109.  
  110.   while (++k < argc && mode > -1) {
  111.     uint8 *p  = argv[k];
  112.     while (*p && mode > -1) {
  113.       if (!mode) {
  114.         if (*p == ':') mode = -1;
  115.         else if (smode && *p != 's' && *p  != 'S') mode = -1;
  116.       }
  117.       if (mode < 0) break;
  118.       else if (mode < 20) {
  119.         if (*p == ':') {
  120.           if (!mode || (mode > 1 && (*drvstr != 'S' || !smode)))
  121.             mode = -1;
  122.           else {
  123.             *pd = '\0';
  124.             if (mode > 1) {
  125.               *drvstr='s';
  126.               *(drvstr+1)=(uint8) atoi((char*)drvstr+1);
  127.             }
  128.             mode = 20;
  129.             pd   = nwpath->buff;
  130.           }
  131.         } else {
  132.           if (++mode == 20) mode = -1;
  133.           else {
  134.             if (*p > 0x60 && *p < 0x7b)
  135.               *pd++ = *p - 0x20;  /* upshift */
  136.             else
  137.               *pd++ = *p;
  138.           }
  139.         }
  140.       } else if (mode == 20) {
  141.         if (*p == '=') mode = 30;
  142.         else if (*p != ' ' && *p != '\t') mode = -2;
  143.       } else if (mode == 30) {
  144.         if (*p != ' ' && *p != '\t') {
  145.           mode = 40;
  146.           continue;
  147.         }
  148.       } else if (mode == 40) {
  149.         if (*p > 0x60 && *p < 0x7b)
  150.           *pd++ = *p - 0x20;  /* upshift */
  151.         else
  152.           *pd++ = *p;
  153.       }
  154.       p++;
  155.     } /* while *p */
  156.   } /* while k */
  157.   if (mode == 30) {
  158.     if (argvmode != 1)
  159.        getcwd((char *)nwpath->buff, sizeof(nwpath->buff));
  160.     mode = 40;
  161.   }
  162.   if (mode && mode != 20 && mode != 40) {
  163.     fprintf(stderr, "Cannot interpret line. errcode=%d\n", mode);
  164.     return(mode < 0 ? mode : -3);
  165.   }
  166.   return(0);
  167. }
  168.  
  169. int func_map(int argc, char *argv[], int mode)
  170. {
  171.   uint8  drvstr[22];
  172.   NWPATH nwpath;
  173.   if (!ipx_init()) argc = 1;
  174.   if (!parse_argv(drvstr, &nwpath, argc, argv, 0, mode)) {
  175.     if (*(nwpath.path) || mode==1) {
  176.       if (do_map(*drvstr - 'A', &nwpath, mode)< 0)
  177.         fprintf(stderr, "MAP Error\n");
  178.     }
  179.     if (mode != 1)
  180.       show_map(drvstr);
  181.     return(0);
  182.   }
  183.   return(1);
  184. }
  185.  
  186.  
  187. /* ------------------------------------------------- */
  188. static int show_search(uint8 *drvstr)
  189. {
  190.   SEARCH_VECTOR          drives;
  191.   SEARCH_VECTOR_ENTRY *p=drives;
  192.   int j=0;
  193.   get_search_drive_vektor(drives);
  194.   while (p->drivenummer != 0xff && j++ < 16) {
  195.     char  path[256];
  196.     char  nwname_path[300];
  197.  
  198.  
  199.     if ( !*drvstr || j == *(drvstr+1)) {
  200.  
  201.       if (p->drivenummer == 0xfe){
  202.         strcpy(path, p->dospath);
  203.       } else {
  204.         *path      = p->drivenummer+'A';
  205.         *(path+1)  = ':';
  206.         strcpy(path+2, p->dospath);
  207.       }
  208.  
  209.       if (p->flags && !(p->flags & 0x80)){
  210.         char *pp=nwname_path;
  211.         *pp++ = '[';
  212.         get_fs_name(p->connid, pp);
  213.         pp   +=strlen(pp);
  214.         *pp++='\\';
  215.         if (get_dir_path(p->dhandle, pp)) {
  216.           strcpy(pp, "ERROR NW");
  217.         }
  218.         pp   += strlen(pp);
  219.         *pp ++= ']';
  220.         *pp   = '\0';
  221.       } else {
  222.         *nwname_path  = '\0';
  223.       }
  224.       printf("SEARCH%2d = %s %s\n", j,  path, nwname_path);
  225.     }
  226.     p++;
  227.   }
  228.   return(0);
  229. }
  230.  
  231. static int set_search(uint8 *drvstr, NWPATH *nwp, int pathmode)
  232. {
  233.   int result=-1;
  234.   SEARCH_VECTOR          drives;
  235.   SEARCH_VECTOR_ENTRY *p=drives;
  236.   int j=0;
  237.   int entry = (*drvstr=='s') ? *(drvstr+1) : 0;
  238.   get_search_drive_vektor(drives);
  239.  
  240.   while (p->drivenummer != 0xff && j++ < 16) {
  241.     if (!entry && (p->drivenummer + 'A' == *drvstr)) entry=j;
  242.     if (p->drivenummer + 'A' == nwp->path[0] && nwp->path[1] == ':'
  243.          && !strcmp(nwp->path+2, p->dospath)) {
  244.       p->drivenummer=0xfe;
  245.       *(p->dospath) = '\0';
  246.     }
  247.     p++;
  248.   }
  249.  
  250.   if (entry > 0) {
  251.     if (entry > 16)  entry = 16;
  252.     if (pathmode == 2 && entry <= j && entry < 16) {  /* insert modus */
  253.       int k=j+1-entry;
  254.       if (j < 16) {
  255.         p++;
  256.         k++;
  257.         j++;
  258.       }
  259.       while (k--) {
  260.         memcpy(p, p-1, sizeof(SEARCH_VECTOR_ENTRY));
  261.         --p;
  262.       }
  263.     }
  264.     if (--entry < j)
  265.       p = drives+entry;
  266.     else (p+1)->drivenummer = 0xff;
  267.     p->flags       = 0;
  268.     p->drivenummer = 0xfe;
  269.     if (pathmode==1)
  270.       *(p->dospath) = '\0';
  271.     else
  272.       strcpy(p->dospath, nwp->path);
  273.     result = set_search_drive_vektor(drives);
  274.   }
  275.   return(result);
  276. }
  277.  
  278. int func_path(int argc, char *argv[], int mode)
  279. {
  280.   uint8  drvstr[22];
  281.   NWPATH nwpath;
  282.   if (!parse_argv(drvstr, &nwpath, argc, argv, 1, mode)) {
  283.     int result=0;
  284.     if (*(nwpath.path) || mode==1)
  285.        result=set_search(drvstr, &nwpath, mode);
  286.     if (mode != 1)
  287.       show_search(drvstr);
  288.     return(result);
  289.   }
  290.   return(1);
  291. }
  292.  
  293. void remove_nwpathes(void)
  294. {
  295.   SEARCH_VECTOR          drives;
  296.   SEARCH_VECTOR_ENTRY *p=drives;
  297.   int j=0;
  298.   get_search_drive_vektor(drives);
  299.   while (p->drivenummer != 0xff && j++ < 16) {
  300.     if (p->flags && !(p->flags & 0x80)){
  301.       p->flags=0;
  302.       p->drivenummer=0xfe;
  303.       *(p->dospath) ='\0';
  304.     }
  305.     ++p;
  306.   }
  307.   set_search_drive_vektor(drives);
  308. }
  309.  
  310.  
  311.  
  312.  
  313.  
  314.